authApp.value('page','updata');
authApp.controller("uploadController",function($scope,$http,$location,$getQueryString,$splice,Upload,$timeout, $cookies){

    //上传pdf文件
    $scope.uploadFiles= function(file, errFiles,index) {
        $scope.f = file;
        $scope.errFile = errFiles && errFiles[0];

        if (file) {
            console.log(file);
            file.upload = Upload.upload({
                url: apis.uploadfile,
                data: {file: file}
            });

            file.upload.then(function (response) {
                console.log(response);
                $timeout(function () {
                    if(response.data.code=="000000"){
                        $scope.uploadFileName = response.data.data.url;
                        $scope.uploadUrl = response.data.data.url
                        $scope.saveresponse();
                    }
                    else
                        alert(response.data.errorMsg);
                });
            }, function (response) {
                if (response.status > 0)
                    $scope.errorMsg = response.status + ': ' + response.data;
            }, function (evt) {
                file.progress = Math.min(100, parseInt(100.0 *
                    evt.loaded / evt.total));
            });
        }
    }

    $scope.getAML=function(){
        var id = $cookies.get('account')
        $http({
            method:'post',
            url:apis.queryApplyFileBySchoolId2,
            data: {'son_target_id':'', 'schoolId': id},
        }).success(function(response){
            if(response.code=="000000"){
                $scope.uploadFileName = response.data.s_employment_distribution_filepath;
                $scope.pId = response.data.p_id;
                $scope.baseList=response.data.base;
                $scope.baseDetailList=response.data.baseDetail;
                $scope.baseScorelList=response.data.baseScore;
                $scope.buildBase1=response.data.buildBase1;
                $scope.buildBase2=response.data.buildBase2;
                // $("input:checkbox[name=buildBase1]").attr("checked",true);
                // $("input:checkbox[name=buildBase2]").attr("checked",true);

            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("服务器打瞌睡了，请稍等！");
        })
    }

    $scope.getAML();
    $scope.saveresponse = function(){
        $http({
            method:'post',
            url:apis.saveApplyFile,
            data:{
                fileUrl:$scope.uploadUrl,
                'son_target_id': '',
                'schoolId': $cookies.get('account'),
                's_score': ''
            },
        }).success(function(response){
            if(response.code=="000000"){
                //alert(response.errorMsg);
               // $scope.getAML();
            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("服务器打瞌睡了，请稍等！");
        })
    }

    $scope.redirect = function(path) {
        // $http({
        // 	method:'get',
        // 	url:apis.downSchoolFile ,
        // 	params:{"path": path},
        // }).success(function(response){
        // 	if(response.code=="000000"){
        // 		//$scope.files
        // 		//$scope.files(response.data[0].p_id)\
        // 		totext(response.data)
        // 	}else{
        // 		alert(response.errorMsg);
        // 	}
        // }).error(function(){
        // 	alert("网络出现故障，请确认网络是否连接");
        // })
        if(typeof(path)=="undefined"||path==""||path==null){
            alert("请先上传文件");
            $scope.getAML();
        }else {
            return window.location.href = apis.downloadsFile + '?path=' + path
        }
    }

    $scope.deletecp = function(pid) {
        if (typeof(pid) == "undefined"||pid==""||pid==null) {
            alert("请先上传文件");
            $scope.getAML();
        } else {
            var obj1 = {'p_id': pid}
            $http({
                method: 'post',
                url: apis.deleteApplyFile,
                data: obj1,
            }).success(function (response) {
                if (response.code == "000000") {
                    alert('自评表删除成功')
                    $scope.getAML();
                } else {
                    alert(response.errorMsg);
                }
            }).error(function () {
                alert("服务器打瞌睡了，请稍等！");
            })
        }
    }

    $scope.submit= function() {

        // $scope.test = $scope.baseDetailList.buildBase;
        // $scope.checkBoxValue = "";
        //     test.each(function(){
        //         checkBoxValue += $(this).val()+",";
        //     })
        //     checkBoxValue = checkBoxValue.substring(0,checkBoxValue.length-1);



            $http({
                method: 'post',
                url: apis.saveApplyFileDetail,
                data:{
                    'schoolId': $cookies.get('account'),
                    'declareType': $scope.baseList.declareType,
                    'schoolName': $scope.baseList.schoolName,
                    'competentDepartment': $scope.baseList.competentDepartment,
                    'schoolCorporation': $scope.baseList.schoolCorporation,
                    'telephone': $scope.baseList.telephone,
                    'phone': $scope.baseList.phone,
                    'mail': $scope.baseList.mail,
                    'schoolAddress': $scope.baseList.schoolAddress,
                    'zipCode':$scope.baseList.zipCode,
                    'schoolWebsite':$scope.baseList.schoolWebsite,

                    'buildBase1':$scope.buildBase1,
                    'buildBase2':$scope.buildBase2,
                    'schoolNature':$scope.baseDetailList.schoolNature,
                    'informationBuild':$scope.baseDetailList.informationBuild,

                    'studentAtSchoolNumAll':$scope.baseDetailList.studentAtSchoolNumAll,
                    'studentAtSchoolNumFive':$scope.baseDetailList.studentAtSchoolNumFive,
                    'studentAtSchoolNumMiddle':$scope.baseDetailList.studentAtSchoolNumMiddle,
                    'studentAtSchoolNumPart':$scope.baseDetailList.studentAtSchoolNumPart,
                    'studentAtSchoolNumOther':$scope.baseDetailList.studentAtSchoolNumOther,

                    'studentEnrolmentNumAll':$scope.baseDetailList.studentEnrolmentNumAll,
                    'studentEnrolmentNumFive':$scope.baseDetailList.studentEnrolmentNumFive,
                    'studentEnrolmentNumMiddle':$scope.baseDetailList.studentEnrolmentNumMiddle,
                    'studentEnrolmentNumPart':$scope.baseDetailList.studentEnrolmentNumPart,
                    'studentEnrolmentNumOther':$scope.baseDetailList.studentEnrolmentNumOther,

                    'studentGraduationNumAll':$scope.baseDetailList.studentGraduationNumAll,
                    'studentGraduationNumFive':$scope.baseDetailList.studentGraduationNumFive,
                    'studentGraduationNumMiddle':$scope.baseDetailList.studentGraduationNumMiddle,
                    'studentGraduationNumPart':$scope.baseDetailList.studentGraduationNumPart,
                    'studentGraduationNumOther':$scope.baseDetailList.studentGraduationNumOther,

                    'financialAppropriationStandard':$scope.baseDetailList.financialAppropriationStandard,
                    'governmentsInvested':$scope.baseDetailList.governmentsInvested,
                    'budgetaryPublicFunds':$scope.baseDetailList.budgetaryPublicFunds,
                    'schoolSponsored':$scope.baseDetailList.schoolSponsored,
                    'cooperativeEnterprise':$scope.baseDetailList.cooperativeEnterprise,
                    'vocationalEducationGroup':$scope.baseDetailList.vocationalEducationGroup,
                    'numPilotOfModernApprenticeship':$scope.baseDetailList.numPilotOfModernApprenticeship,
                    'personPilotOfModernApprenticeship':$scope.baseDetailList.personPilotOfModernApprenticeship,
                    'foreignCooperationProjects':$scope.baseDetailList.foreignCooperationProjects,
                    'provincialBrandCharacteristicSpecialty':$scope.baseDetailList.provincialBrandCharacteristicSpecialty,
                    'provincialModernizationProfessionalGroup':$scope.baseDetailList.provincialModernizationProfessionalGroup,
                    'systemPilotProject':$scope.baseDetailList.systemPilotProject,
                    'projectEstablishment':$scope.baseDetailList.projectEstablishment,
                    'completionCourse':$scope.baseDetailList.completionCourse,
                    'countryEditorInChief':$scope.baseDetailList.countryEditorInChief,
                    'provinceEditorInChief':$scope.baseDetailList.provinceEditorInChief,
                    'papersInCoreJournals':$scope.baseDetailList.papersInCoreJournals,
                    'teachingAchievementAward':$scope.baseDetailList.teachingAchievementAward,
                    'highDemonstrationTrainingBase':$scope.baseDetailList.highDemonstrationTrainingBase,
                    'modernTrainingBase':$scope.baseDetailList.modernTrainingBase,
                    'studentToTeacherRatio':$scope.baseDetailList.studentToTeacherRatio,
                    'numberOfFulltimeTeachers':$scope.baseDetailList.numberOfFulltimeTeachers,
                    'percentageOfFulltimeTeachers':$scope.baseDetailList.percentageOfFulltimeTeachers,
                    'numberOfDoubleQualifiedTeachers':$scope.baseDetailList.numberOfDoubleQualifiedTeachers,
                    'percentageOfDoubleQualifiedTeachers':$scope.baseDetailList.percentageOfDoubleQualifiedTeachers,
                    'graduateStudentRatio':$scope.baseDetailList.graduateStudentRatio,
                    'seniorProfessionalTitleRatio':$scope.baseDetailList.seniorProfessionalTitleRatio,
                    'numberOfTeachersBasicCourses':$scope.baseDetailList.numberOfTeachersBasicCourses,
                    'percentageOfTeachersBasicCourses':$scope.baseDetailList.percentageOfTeachersBasicCourses,
                    'cityFamousTeacher':$scope.baseDetailList.cityFamousTeacher,
                    'provinceFamousTeacher':$scope.baseDetailList.provinceFamousTeacher,
                    'nationalSkillsCompetitionAwards':$scope.baseDetailList.nationalSkillsCompetitionAwards,
                    'nationalSkillsCompetitionAwardsFirst':$scope.baseDetailList.nationalSkillsCompetitionAwardsFirst,
                    'provincialSkillsCompetitionAwards':$scope.baseDetailList.provincialSkillsCompetitionAwards,
                    'provincialSkillsCompetitionAwardsFirst':$scope.baseDetailList.provincialSkillsCompetitionAwardsFirst,
                    'intermediateCertificateAcquisitionRate':$scope.baseDetailList.intermediateCertificateAcquisitionRate,
                    'advancedCertificateAcquisitionRate':$scope.baseDetailList.advancedCertificateAcquisitionRate,
                    'educationalAndTeachingCompetitionAwarded':$scope.baseDetailList.educationalAndTeachingCompetitionAwarded,
                    'employmentRateOfGraduates':$scope.baseDetailList.employmentRateOfGraduates,
                    'counterpartEmploymentRate':$scope.baseDetailList.counterpartEmploymentRate,
                    'localEmploymentRate':$scope.baseDetailList.localEmploymentRate,
                    'innovationAndEntrepreneurshipCompetitionAwards':$scope.baseDetailList.innovationAndEntrepreneurshipCompetitionAwards,
                    'civilizationCompetitionAwards':$scope.baseDetailList.civilizationCompetitionAwards,
                    'annualSocialTraining':$scope.baseDetailList.annualSocialTraining,
                    'socialServiceIncome':$scope.baseDetailList.socialServiceIncome,
                    'authorizedPatentNumber':$scope.baseDetailList.authorizedPatentNumber,
                    'transferOfResults':$scope.baseDetailList.transferOfResults,

                    'purposeOfSchool':$scope.baseScorelList.purposeOfSchool,
                    'purposeOfSchoolRemark':$scope.baseScorelList.purposeOfSchoolRemark,
                    'thoughtOfSchool':$scope.baseScorelList.thoughtOfSchool,
                    'thoughtOfSchoolRemark':$scope.baseScorelList.thoughtOfSchoolRemark,
                    'developmentPlan':$scope.baseScorelList.developmentPlan,
                    'developmentPlanRemark':$scope.baseScorelList.developmentPlanRemark,
                    'policySupport':$scope.baseScorelList.policySupport,
                    'policySupportRemark':$scope.baseScorelList.policySupportRemark,
                    'fundingGuarantee':$scope.baseScorelList.fundingGuarantee,
                    'fundingGuaranteeRemark':$scope.baseScorelList.fundingGuaranteeRemark,
                    'foundationOfConstruction':$scope.baseScorelList.foundationOfConstruction,
                    'foundationOfConstructionRemark':$scope.baseScorelList.foundationOfConstructionRemark,
                    'schoolEnterpriseCooperation':$scope.baseScorelList.schoolEnterpriseCooperation,
                    'schoolEnterpriseCooperationRemark':$scope.baseScorelList.schoolEnterpriseCooperationRemark,
                    'collectivizeSchoolRunning':$scope.baseScorelList.collectivizeSchoolRunning,
                    'collectivizeSchoolRunningRemark':$scope.baseScorelList.collectivizeSchoolRunningRemark,
                    'internationalCoOperation':$scope.baseScorelList.internationalCoOperation,
                    'internationalCoOperationRemark':$scope.baseScorelList.internationalCoOperationRemark,
                    'moralQualityTraining':$scope.baseScorelList.moralQualityTraining,
                    'moralQualityTrainingRemark':$scope.baseScorelList.moralQualityTrainingRemark,
                    'cultivationOfProfessionalSpirit':$scope.baseScorelList.cultivationOfProfessionalSpirit,
                    'cultivationOfProfessionalSpiritRemark':$scope.baseScorelList.cultivationOfProfessionalSpiritRemark,
                    'mentalHealthEducation':$scope.baseScorelList.mentalHealthEducation,
                    'mentalHealthEducationRemark':$scope.baseScorelList.mentalHealthEducationRemark,
                    'constructionPlanning':$scope.baseScorelList.constructionPlanning,
                    'constructionPlanningRemark':$scope.baseScorelList.constructionPlanningRemark,
                    'professionalGroupConstruction':$scope.baseScorelList.professionalGroupConstruction,
                    'professionalGroupConstructionRemark':$scope.baseScorelList.professionalGroupConstructionRemark,
                    'trainingBase':$scope.baseScorelList.trainingBase,
                    'trainingBaseRemark':$scope.baseScorelList.trainingBaseRemark,
                    'comprehensiveTraining':$scope.baseScorelList.comprehensiveTraining,
                    'comprehensiveTrainingRemark':$scope.baseScorelList.comprehensiveTrainingRemark,
                    'curriculumDevelopment':$scope.baseScorelList.curriculumDevelopment,
                    'curriculumDevelopmentRemark':$scope.baseScorelList.curriculumDevelopmentRemark,
                    'teachingModel':$scope.baseScorelList.teachingModel,
                    'teachingModelRemark':$scope.baseScorelList.teachingModelRemark,
                    'leadershipRanks':$scope.baseScorelList.leadershipRanks,
                    'leadershipRanksRemark':$scope.baseScorelList.leadershipRanksRemark,
                    'middleManagementTeam':$scope.baseScorelList.middleManagementTeam,
                    'middleManagementTeamRemark':$scope.baseScorelList.middleManagementTeamRemark,
                    'qualityOfTeachers':$scope.baseScorelList.qualityOfTeachers,
                    'qualityOfTeachersRemark':$scope.baseScorelList.qualityOfTeachersRemark,
                    'backboneOfFamousTeachers':$scope.baseScorelList.backboneOfFamousTeachers,
                    'backboneOfFamousTeachersRemark':$scope.baseScorelList.backboneOfFamousTeachersRemark,
                    'schoolProspectus':$scope.baseScorelList.schoolProspectus,
                    'schoolProspectusRemark':$scope.baseScorelList.schoolProspectusRemark,
                    'institutionalSystem':$scope.baseScorelList.institutionalSystem,
                    'institutionalSystemRemark':$scope.baseScorelList.institutionalSystemRemark,
                    'systemImplementation':$scope.baseScorelList.systemImplementation,
                    'systemImplementationRemark':$scope.baseScorelList.systemImplementationRemark,
                    'monitoringSystem':$scope.baseScorelList.monitoringSystem,
                    'monitoringSystemRemark':$scope.baseScorelList.monitoringSystemRemark,
                    'monitoringMeasures':$scope.baseScorelList.monitoringMeasures,
                    'monitoringMeasuresRemark':$scope.baseScorelList.monitoringMeasuresRemark,
                    'coreCulture':$scope.baseScorelList.coreCulture,
                    'coreCultureRemark':$scope.baseScorelList.coreCultureRemark,
                    'campusEnvironment':$scope.baseScorelList.campusEnvironment,
                    'campusEnvironmentRemark':$scope.baseScorelList.campusEnvironmentRemark,
                    'comprehensiveQuality':$scope.baseScorelList.comprehensiveQuality,
                    'comprehensiveQualityRemark':$scope.baseScorelList.comprehensiveQualityRemark,
                    'skillLevel':$scope.baseScorelList.skillLevel,
                    'skillLevelRemark':$scope.baseScorelList.skillLevelRemark,
                    'competitivePower':$scope.baseScorelList.competitivePower,
                    'competitivePowerRemark':$scope.baseScorelList.competitivePowerRemark,
                    'socialServices':$scope.baseScorelList.socialServices,
                    'socialServicesRemark':$scope.baseScorelList.socialServicesRemark,
                    'socialEvaluation':$scope.baseScorelList.socialEvaluation,
                    'socialEvaluationRemark':$scope.baseScorelList.socialEvaluationRemark,
                    'demonstrationAndGuidance':$scope.baseScorelList.demonstrationAndGuidance,
                    'demonstrationAndGuidanceRemark':$scope.baseScorelList.demonstrationAndGuidanceRemark,



             },
            }).success(function (response) {
                if (response.code == "000000") {
                    alert('添加自评表信息成功！')
                    $scope.getAML();
                } else {
                    alert(response.errorMsg);
                }
            }).error(function () {
                alert("服务器打瞌睡了，请稍等！");
            })
        }

})
